using Sustainalytics.Entities.ESGRatings;
using Sustainalytics.ESG.Entities;
using Sustainalytics.ESGRatings.BusinessLogic;
using Sustainalytics.Utils;
using System;
using Xunit;

namespace Sustainalytics.CRT.Synchronization.Tests
{

    [Trait("Category", "Unit")]
    public class FocusedRatingsAssementTest
    {

        private readonly EsgFocusThresholds[] thresholds;

        public FocusedRatingsAssementTest()
        {
            thresholds = new EsgFocusThresholds[]
                                   {
                                       new EsgFocusThresholds { Id = Guid.NewGuid(), Value = "Laggard", PeerGroup = "Homebuilders", PeerGroupId = new Guid("0BFA13EB-A628-4178-AC02-D99D077BCF53"), LowerBound = 0, UpperBound = 25 },
                                       new EsgFocusThresholds { Id = Guid.NewGuid(), Value = "Underperformer", PeerGroup = "Homebuilders", PeerGroupId = new Guid("0BFA13EB-A628-4178-AC02-D99D077BCF53"), LowerBound = 25, UpperBound = 50 },
                                       new EsgFocusThresholds { Id = Guid.NewGuid(), Value = "Average Performer", PeerGroup = "Homebuilders", PeerGroupId = new Guid("0BFA13EB-A628-4178-AC02-D99D077BCF53"), LowerBound = 50, UpperBound = 75 },
                                       new EsgFocusThresholds { Id = Guid.NewGuid(), Value = "Outperformer", PeerGroup = "Homebuilders", PeerGroupId = new Guid("0BFA13EB-A628-4178-AC02-D99D077BCF53"), LowerBound = 75, UpperBound = 84 },
                                       new EsgFocusThresholds { Id = Guid.NewGuid(), Value = "Leader", PeerGroup = "Homebuilders", PeerGroupId = new Guid("0BFA13EB-A628-4178-AC02-D99D077BCF53"), LowerBound = 84, UpperBound = 101 },
                                   };
        }

        [Fact]
        public void Should_return_an_assesment_when_for_a_score_in_first_range()
        {
            var actual = FocusedRatingsAssessmentManager.GetAssessment(10d, thresholds);
            var expected = new RPAssessment { Id = 5, Name = thresholds[0].Value };
            Assert.Equal(expected, actual);
        }

        [Fact]
        public void Should_return_an_assesment_type_5_when_for_a_score_in_lower_range()
        {
            var actual = FocusedRatingsAssessmentManager.GetAssessment(10d, thresholds);
            var expected = new RPAssessment { Id = 5, Name = thresholds[0].Value };
            Assert.Equal(expected.Dump(), actual.Dump());
        }


        [Theory,
         InlineData(-0.01f),
         InlineData(101f)]
        public void Should_return_an_empty_assesment_when_Score_not_in_any_gap(double score)
        {
            var actual = FocusedRatingsAssessmentManager.GetAssessment(score, thresholds);
            var expected = new RPAssessment();
            Assert.Equal(expected.Dump(), actual.Dump());
        }
    }


}